import { request } from "@/utils/request";

export interface Classify {
  name: string;
  _id: string;
  sort: number;
  picurl: string;
  select: boolean;
  updateTime: string;
}
export interface ClassifyWallList {
  description: string;
  _id: string;
  classid: string;
  smallPicurl: string;
  picurl?: string;
  score: string;
  nickname: string;
  tabs: string[];
  userScore?: string;
}
export interface SetupScore {
  id: string;
}

export const apiGetClassify = (
  data: { select?: boolean; pageSize?: number } = {}
) => {
  return request<Classify[]>("/classify", {
    data,
    catch: () => {
      return {
        data: Array(8)
          .fill({
            name: "全部",
            _id: "1234567",
            select: true,
            sort: 0,
            picurl:
              "https://img2.baidu.com/it/u=3209353042,356122753&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
            updateTime: new Date(),
          })
          .map((item) => ({ ...item, _id: item._id + Math.random() })),
        errCode: 0,
        errMsg: "",
      };
    },
  });
};

export const apiGetClassifyWallList = (
  data: { classid?: string; pageSize?: number; pageNum?: number } = {}
) => {
  return request<ClassifyWallList[]>("/wallList", {
    data,
    catch: () => {
      return {
        data: Array(12)
          .fill({
            nickname: "全部",
            _id: "1234567",
            classid: "1234567",
            smallPicurl:
              "https://img2.baidu.com/it/u=3209353042,356122753&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
            description: `${Date.now()}`,
            tabs: ["好", "差"],
            score: "5",
          })
          .map((item) => ({ ...item, _id: item._id + Math.random() })),
        errCode: 0,
        errMsg: "",
      };
    },
  });
};

export const apiSetupScore = (data: {
  classid: string;
  wallId: string;
  userScore: string;
}) => {
  return request<SetupScore>("/setupScore", {
    data,
    catch: () => {
      return {
        data: {
          id: "1234567",
        },
        errCode: 0,
        errMsg: "",
      };
    },
  });
};

export const apiDetailWall = (data: { id: string }) => {
  return request<ClassifyWallList[]>("/detailWall", {
    data,
    catch: () => {
      return {
        data: [
          {
            nickname: "全部",
            _id: "1234567",
            classid: "1234567",
            smallPicurl:
              "https://img2.baidu.com/it/u=3209353042,356122753&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
            description: `${Date.now()}`,
            tabs: ["好", "差"],
            score: "5",
          },
        ],
        errCode: 0,
        errMsg: "",
      };
    },
  });
};
